package com.app.xinfadi.ui.lead_role_ourchase_plan;



import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.app.xinfadi.R;
import com.app.xinfadi.base.BaseFragment;
import com.app.xinfadi.ui.purchase_price.PurchasePriceFragment;
import com.sevenheaven.segmentcontrol.SegmentControl;

import java.util.ArrayList;

/**
 * function:审批列表 -- 领导角色
 * Created by Wutengfei on 2016/1/25..
 */
public  class LeadRoleExamineAndApproveListFragment extends BaseFragment {
    private static final String TAG = LeadRoleExamineAndApproveListFragment.class.getSimpleName();
    private View view;
    private ViewPager mViewPager;
    private ArrayList<Fragment> waitDealingFragmentList;
    private FragmentPagerAdapter mAdapter;
    private ViewPager.OnPageChangeListener mPagerChangeListener;
    private SegmentControl segment_control;

    public static LeadRoleExamineAndApproveListFragment getInstance() {
        LeadRoleExamineAndApproveListFragment instance = new LeadRoleExamineAndApproveListFragment();
        Bundle args = new Bundle();
//      args.putString("status", status);
        instance.setArguments(args);
        return instance;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.lead_role_examine_and_approve_list_layout_fragment, null);
        initView();
        initData();
        return view;
    }

    private void initView() {
        mViewPager = (ViewPager) view.findViewById(R.id.id_viewpager);
        mViewPager.setOffscreenPageLimit(3);
        waitDealingFragmentList = new ArrayList<>();
        waitDealingFragmentList.add(PurchasePriceFragment.getInstance(2,"11"));
        waitDealingFragmentList.add(PurchasePriceFragment.getInstance(2,"21"));
        waitDealingFragmentList.add(PurchasePriceFragment.getInstance(2,"03"));

        mAdapter = new FragmentPagerAdapter(getChildFragmentManager()) {

            @Override
            public int getCount() {
                return waitDealingFragmentList.size();
            }

            @Override
            public Fragment getItem(int arg0) {
                return waitDealingFragmentList.get(arg0);
            }
        };

        mViewPager.setAdapter(mAdapter);
        mPagerChangeListener = new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                segment_control.setSelectedIndex(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        };
        mViewPager.addOnPageChangeListener(mPagerChangeListener);

        segment_control = (SegmentControl) view.findViewById(R.id.segment_control);
        segment_control.setOnSegmentControlClickListener(new SegmentControl.OnSegmentControlClickListener() {
            @Override
            public void onSegmentControlClick(int index) {
                mViewPager.setCurrentItem(index);
            }
        });
    }

    private void initData() {

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mViewPager.removeOnPageChangeListener(mPagerChangeListener);
    }
}
